<?php
/* 
 * name        : Internal » User » Login
 * description : Allows a user to login or out of the website.
 * context     : page
 * 
 */
global $smarty;

$default_config = array(
	'user_field'     => 'username_or_email',
	'user_label'     => 'Username or email address',
	'password_label' => 'Password',
	'login_label'    => 'Login',
	'body_intro'     => '<p>Enter your username and pasword below to login.</p>',
	'body_error'     => '<p>Your details were incorrect.  Please try again.</p>',
	'body_success'   => '<p>You\'re now logged into the website.</p>'
);

$config = array_merge($default_config, parse_config($config));

if (isset($_GET['logout'])) {
	unset($_SESSION['login']);
	header('Location: ' . str_replace('?logout', '', $_SERVER['REQUEST_URI']));
	exit;
}

if ($_POST and isset($_SESSION['login']) and $_REQUEST['page']) {
	header('Location: ' . $_REQUEST['page']);
	exit;
}

$smarty->assign('config', $config);
$smarty->display(dirname(__FILE__) . '/templates/login.tpl.html');
